package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class studao {

	List<People> peolist = new ArrayList<People>();
	public int keyid;

	public StuDao() {

		try {
			Class.forName("com.mysql.cj.jdbc.Driver");
			Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/students","root","1234");
			String sql = "select * from student ";
			PreparedStatement statement = connection.prepareStatement(sql);
			ResultSet rs = statement.executeQuery();
			while(rs.next()){

				int id = rs.getInt(1);
				String name = rs.getString(2);
				String sex = rs.getString(3);
				int age = rs.getInt(4);
				String department = rs.getString(5);
				String type = rs.getString(6);
				String year = rs.getString(7);

				peolist.add(new People(id,name,sex,age,department,type,year));
				keyid=id;

			}

			try{
				connection.close();
				statement.close();
			}catch (Exception e){
				e.printStackTrace();
			}


		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public List<People> getAll() {
		return peolist;
	}

	public int getkeyid() {
		return keyid;
	}

}
